import requests
from lxml import etree
from multiprocessing import Pool,Manager
import time

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3702.0 Safari/537.36"
}


def info(url,q):
    # print('开始下载%s'%url)
    response = requests.get(url,headers=headers)
    if response.status_code == 200:
        text = response.text
        html = etree.HTML(text)
        res = html.xpath('//table[@class="tablelist"]//tr/td/a/text()')
        # print(res)
        for i in res:
            # print(res)
            # q.put(i)
            # time.sleep(1)
            print('%s下载完成--%s'% (url,i))
if __name__ == '__main__':
    start= time.time()
    # 创建进程池
    po = Pool(8)
    # 实例化
    q = Manager().Queue()

    url = "https://hr.tencent.com/position.php?lid=2175&start=%s"
    url_list = [url % i for i in range(0,201,10)]
    for url in url_list:
        po.apply_async(func=info,args=(url,q))
    po.close()
    po.join()

    while not q.empty():
        print(q.get_nowait())

    end = time.time()-start
    print(end)
